package cn.ydt.ydt.user.webapi.service;

import cn.ydt.ydt.common.pojo.domain.UserJwtVO;
import cn.ydt.ydt.common.utils.FileNameUtils;
import cn.ydt.ydt.pojo.user.model.User;
import cn.ydt.ydt.pojo.user.vo.UserShowInfoVO;

import cn.ydt.ydt.user.service.IVolunteerService;
import cn.ydt.ydt.user.webapi.mapper.UserMapper;
import cn.ydt.ydt.user.webapi.mapper.VolunteerMapper;
import cn.ydt.ydt.user.webapi.utils.SecurityContextUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@DubboService
@Service
@Slf4j
public class VolunteerServiceImpl implements IVolunteerService {
    @Autowired
    VolunteerMapper volunteerMapper;

    @Autowired
    UserMapper userMapper;

    @Override
    public List<Integer> volunteerUserId() {

        return volunteerMapper.volunteerUserId();
    }

    @Override
    public List<User> volunteerInfo() {
        List<User> users = volunteerMapper.volunteerInfo();
        for (User u : users) {
            String img = u.getUserIcon();
            u.setUserIcon(FileNameUtils.filePath(img));
        }
        return users;
    }

    @Override
    public List<User> volunteerApplyInfo() {
        List<User> users = userMapper.selectByIsVolunteer();
        for (User u : users) {
            String img = u.getUserIcon();
            u.setUserIcon(FileNameUtils.filePath(img));
        }
        return users;
    }



    @Override
    public int isVolunteerApplication() {
            UserJwtVO userInfo = SecurityContextUtils.getUserInfo();
            return volunteerMapper.isVolunteerApplication(userInfo.getUserId());
    }


    @Override
    public int isVolunteerSetAccess(Long userId) {
        return volunteerMapper.isVolunteerSetAccess(userId);
    }

    @Override
    public int isVolunteerSetFail(Long userId) {
        return volunteerMapper.isVolunteerSetFail(userId);
    }


}
